package com.dimeng.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.dimeng.R;
import com.dimeng.entity.CompanySearchViewCache;
import com.dimeng.entity.ResultEntity;

/**
 * @author write by ccn<br>
 *         <b>helloandroid100@gmail.com</b>
 * @version 0.1;2012-5-18 下午5:30:44<br>
 *          descrition:公司搜索结果的数据适配器
 */
public class CompanySearchResultAdapter extends ArrayAdapter<ResultEntity> {
	public CompanySearchResultAdapter(Context context,List<ResultEntity> searchResults) {
		super(context, 0, searchResults);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Activity activity = (Activity) getContext();
		// Inflate the views from XML
		View companyRowView = convertView;// 公司搜索结果选项视图
		ResultEntity searchResult = getItem(position);
		CompanySearchViewCache companySearchViewCache;
		if (companyRowView == null) {
			LayoutInflater inflater = activity.getLayoutInflater();
			companyRowView = inflater.inflate(
					R.layout.company_search_list_item, null);
			companySearchViewCache = new CompanySearchViewCache(companyRowView);
			companyRowView.setTag(companySearchViewCache);
		} else {
			companySearchViewCache = (CompanySearchViewCache) companyRowView
					.getTag();
		}
		TextView companyNameView = companySearchViewCache.getCompanyNameView();
		companyNameView.setText(Html.fromHtml(searchResult.getCompanyName()));
		TextView businessModelView = companySearchViewCache.getBusinessModelView();
		businessModelView.setText(searchResult.getBusinessModeName());
		TextView mainBusinessView = companySearchViewCache
				.getMainBusinessView();
		mainBusinessView.setText(searchResult.getMainBusiness());
		TextView companyAddrView = companySearchViewCache.getCompanyAddrView();
		companyAddrView.setText(searchResult.getCompanyAddr());

		return companyRowView;
	}
}
